#include <stdio.h>
#include "aimage.h"
#include "accumulate.h"
#include "aimage_utils.h"
#include "aimage_dcraw.h"
#include "aimage_ppm.h"
#include <assert.h>
#include <stdlib.h>

int main( int argc, char *argv[] )
{
	bool first=true;
	int i;
	AIMAGE frame;
	AIMAGE hotmap;

	for ( i = 1; i < argc; ++i )
	{
		fprintf(stderr,"Hotmap reading %s\n", argv[i] );
		AIMAGE_DCRAW_UTILS::load( frame, argv[ i ] );
		
		if ( first )
		{
			int width, height;
			frame.get_dim( width, height );
			hotmap.alloc_image( width, height );
			AIU::cls( hotmap, 0, 0, 0 );
			first = false;
		}

		AIMAGE::const_iterator src_cur, src_end;
		AIMAGE::iterator dst_cur, dst_end;

		src_cur = frame.const_begin();
		src_end = frame.const_end();
		dst_cur = hotmap.begin();
		dst_end = hotmap.end();

		while ( src_cur != src_end )
		{
			APIXEL ps, pd;
			ps=*src_cur;
			pd=*dst_cur;
			if ( ps.r > FULL_INT / 4 )
			{
				pd.r= FULL_INT;
			}
			if ( ps.g > FULL_INT / 4 )
			{
				pd.g= FULL_INT;
			}
			if ( ps.b > FULL_INT / 4 )
			{
				pd.b = FULL_INT;
			}
			*dst_cur = pd;
			++src_cur;
			++dst_cur;
		}
	}
	assert( !first );

	AIMAGE_PPM_UTILS::save( hotmap, "hotmap.ppm", false );

}

